import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { timer } from 'rxjs';

import { WindowService, ThemeService } from '@core/base';
import { ConfirmModalService } from '@core/base/service/confirm-modal.service';
import { NzMessageService } from 'ng-zorro-antd/message';

@Component({
  selector: 'app-base-user-profile',
  templateUrl: './user-profile.component.html',
  styleUrls: ['./user-profile.component.less']
})
export class UserProfileComponent implements OnInit {
  themeValue!: string;
  constructor(
    protected router: Router,
    private confirmModalSrc: ConfirmModalService,
    private windowSrc: WindowService,
    private themeSrc: ThemeService,
    private messageSrc: NzMessageService
  ) {}

  ngOnInit(): void {
    this.themeValue = this.themeSrc.currentTheme;
  }

  onThemeChanged(event: any): void {
    this.themeSrc.publish(event);
  }

  cleanCache(): void {
    this.confirmModalSrc.danger('清除缓存后，需要重新登录系统。').subscribe(ok => {
      if (ok) {
        // 确认操作
        this.windowSrc.clearSessionStorage();
        this.windowSrc.clearStorage();
        this.messageSrc.success('清除缓存成功');
        timer(100).subscribe(() => {
          // 重新登录
          // TODO
        });
      }
    });
  }

  logout(): void {
    this.messageSrc.success('退出系统');
  }
}
